<!-- 立项管理 -->
<template>
	<view>
		<bg-search placeholder="请输入项目名称" @search="searchHandler">
		</bg-search>
		<view class="p-3">
			<u-list @scrolltolower="loadMore()" style="height: calc(100vh - 250rpx);">
				<u-list-item>
					<view class="bt-block mb-3"  @click="onTap(p)" v-for="(p, i) in dataList" :key="i" :border="i<dataList.length-1">
						<bg-cell2 :label="`编号：${p.projectNo}`" :border="false" :show-arrow="true">
						</bg-cell2>
						<view class="bt-line-1 mx-3"></view>
						<bg-cell :border="false">
							<bg-desc label="项目名称" :value="p.projectName"></bg-desc>
							<bg-desc label="合同金额" :value="p.contractAmount"></bg-desc>
							<bg-desc label="创建时间" :value="p.createTime"></bg-desc>
						</bg-cell>
					</view>
				</u-list-item>
			</u-list>
			
			
		</view>
		
	</view>
</template>

<script>
	import {getProject} from "@/api/project.js"
	export default {
		onNavigationBarButtonTap(e){
			uni.navigateTo({
				url:"/pages/project/project/project"
			})
		},
		data() {
			return {
				total:100,
				params:{
					projectName:'',
					pageNum:1,
					pageSize:100
				},
				dataList:[],
			}
		},
		mounted() {
			this.getData()
			uni.$on('refresh-opener', ()=>{
				this.params.pageNum = 1;
				this.dataList = []
				this.getData()
			})
		},
		methods: {
			searchHandler(e){
				this.params.projectName = e;
				this.params.pageNum = 1;
				this.dataList = []
				this.getData()
			},
			getData(){
				getProject(this.params).then(res=>{
					this.dataList = [...this.dataList, ...res.data.rows];
					this.total = res.data.total;
				})
			},
			loadMore(){
				console.log("more")
				if(this.dataList.length < this.total){
					this.params.pageNum  += 1
					this.getData()
				}
			},
			onTap(obj){
				uni.navigateTo({
					url:"/pages/project/project/detail",
					success:function(res) {
						res.eventChannel.emit("acceptDataFromOpener", {"data": obj})
					}
				})
			}
		}
	}
</script>

<style>
.search-reslut {
	
}
</style>
